#!/usr/bin/python
#
# main.py
# Copyright (C) Ethan Osten 2007 <senoki@gmail.com>
# 
# dieu-add-post.py is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# main.py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with main.py.  If not, write to:
# 	The Free Software Foundation, Inc.,
# 	51 Franklin Street, Fifth Floor
# 	Boston, MA  02110-1301, USA.

import sys
import dbus

try: arguments = sys.argv[1]
except IndexError:
	arguments = ''

arguments = arguments.split('&')

try: url = arguments[1]
except IndexError:
	url = ''

try: title = arguments[3]
except IndexError:
	title = ''

try: extended = arguments[5]
except IndexError:
	extended = ''

surl = url.split('%20')
furl = ''
for word in surl:
    furl += word + ' '

stitle = title.split('%20')
ftitle = ''
for word in stitle:
    ftitle += word + ' '

sextended = extended.split('%20')
fextended = ''
for word in sextended:
    fextended += word + ' '

bus = dbus.SessionBus()

dieu = bus.get_object('org.gnome.Dieu', '/org/gnome/Dieu')

dieu.AddBookmark(ftitle, furl, fextended, '')
